package com.sh.data.engine.domain.normalization.modeldesign.model.model.enums;

import com.sh.data.engine.domain.normalization.modeldesign.model.model.domain.StorageDomain;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 字段枚举
 *
 * @author : changkong
 * @date : 2022/3/6
 */
public enum SapFieldTypeEnum {
    TINYINT("TINYINT"),
    SMALLINT("SMALLINT"),
    INT("INTEGER"),
    BIGINT("BIGINT"),

    FLOAT("REAL"),
    DOUBLE("DOUBLE"),
    DECIMAL("DECIMAL"),

    TIMESTAMP("TIMESTAMP"),

    //  CHAR("varchar"),
    STRING("TEXT"),

    // UNICODE 1-5000
    VARCHAR("NVARCHAR"),

    DATE("DATE"),

    // sap boolean : true false unknown(null)
    BOOLEAN("BOOLEAN"),

    // binary string,5kb limit
    BINARY("BINARY");

    // binary fill 2gb limit
    // BLOB("blob");

    private final String dbFieldType;

    SapFieldTypeEnum(String dbFieldType) {
        this.dbFieldType = dbFieldType;
    }

    public static List<String> getMdAllFieldType() {
        SapFieldTypeEnum[] values = SapFieldTypeEnum.values();
        return Arrays.stream(values).map(i -> i.dbFieldType).collect(Collectors.toList());
    }

    public String getDbFieldType() {
        return dbFieldType;
    }

    public static List<StorageDomain.FieldType> getAllFieldType() {
        SapFieldTypeEnum[] values = SapFieldTypeEnum.values();
        return Arrays.stream(values)
            .map(i -> new StorageDomain.FieldType(i.dbFieldType, i.name()))
            .collect(Collectors.toList());
    }
}
